from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from student import page
from student.base.base import Base
from time import sleep

paper_test = None
paper_test2 = None


class PageWebOrder(Base):
    # 登入
    def page_web_login_btn(self):
        self.base_click(page.student_login_btn)

    # 点击基础任务
    def page_web_task(self):
        sleep(1)
        self.base_click(page.student_login_task)

    # 查看试卷 查看完关闭该窗口
    def page_web_view(self):
        sleep(1)
        main_window = self.driver.current_window_handle
        # self.base_click(page.student_login_view)
        # sleep(2)
        # new_window = self.base_switch_to_new_window(main_window)
        # if new_window:
        #     self.driver.close()
        #
        # # 切换回主窗口

        self.base_click(page.student_login_view)
        self.base_switch_to_window()
        sleep(3)
        self.driver.close()
        self.driver.switch_to.window(main_window)
        main_window = None

    # 开始答题
    def page_web_start(self):
        sleep(2)
        self.base_click(page.student_login_start)

    # 提交试卷
    def page_web_submit(self):
        sleep(1)
        self.base_switch_to_window()
        self.base_click(page.student_login_submit)

    # 返回考试记录
    def page_web_return(self):
        sleep(5)
        self.base_click(page.student_login_return)

    # 点击试卷中心
    def page_web_shijuan(self):
        sleep(1)
        self.base_click(page.student_login_shijuan)

    # 固定试卷
    def page_web_gdsj(self):
        sleep(1)
        self.base_click(page.student_login_gdsj)

    # 试卷学科-语文
    def page_web_chinese(self):
        sleep(1)
        self.base_click(page.student_login_chinese)

    # 开始答题
    def page_web_startwrite(self):
        sleep(1)
        self.base_click(page.student_login_startwrite)

    # 提交
    def page_web_tijiao(self):
        sleep(1)
        self.base_switch_to_window()
        self.base_click(page.student_login_tijiao)

    # 返回2
    def page_web_return2(self):
        sleep(1)
        self.base_click(page.student_login_return2)

    # 视频课堂
    def page_web_video_class(self):
        sleep(1)
        self.base_click(page.student_login_video_class2)
        self.base_click(page.student_login_chinese2)
        main_window = self.driver.current_window_handle
        sleep(3)
        self.base_click(page.student_login_video2)
        sleep(3)
        new_window = self.base_switch_to_new_window(main_window)
        sleep(3)
        if new_window:
            self.driver.close()

        # 切换回主窗口
        self.driver.switch_to.window(main_window)
        main_window = None
        new_window = None

    # 智能训练
    def page_web_training(self):
        sleep(1)
        self.base_click(page.student_login_training)
        self.base_click(page.student_login_generate)
        sleep(3)
        # 获取文本 智能训练--
        wenben1 = self.base_get_text(page.student_login_sjname)
        sleep(3)
        self.base_click(page.student_login_answer)
        sleep(1)
        self.base_switch_to_window()
        sleep(2)
        # self.base_click(page.student_login_A)
        self.base_click(page.student_login_B)
        # self.base_click(page.student_login_C1)
        # self.base_click(page.student_login_C2)
        # self.base_click(page.student_login_C3)
        # self.base_click(page.student_login_C4)
        # self.base_click(page.student_login_D1)
        # self.base_click(page.student_login_D2)
        # self.base_click(page.student_login_D3)
        # self.base_click(page.student_login_D4)
        # self.base_click(page.student_login_E)
        # self.base_click(page.student_login_F)
        sleep(1)
        self.base_click(page.student_login_tijiao2)
        sleep(1)
        self.base_click(page.student_login_return3)
        return wenben1

    # 考试记录
    def page_web_record(self):
        sleep(1)
        self.base_click(page.student_login_record)
        sleep(2)
        self.base_click(page.student_login_chinese3)
        main_window = self.driver.current_window_handle
        self.base_click(page.student_login_view2)
        sleep(3)
        new_window = self.base_switch_to_new_window(main_window)
        sleep(3)
        if new_window:
            self.driver.close()

        # 切换回主窗口
        self.driver.switch_to.window(main_window)
        main_window = None
        new_window = None
        wenben2 = self.base_get_text(page.student_login_sjname2)
        return wenben2

    # 考试记录-数学
    def page_web_record_mathe(self):
        sleep(1)
        self.base_click(page.student_login_mathe)
        main_window = self.driver.current_window_handle
        self.base_click(page.student_login_view3)
        new_window = self.base_switch_to_new_window(main_window)
        sleep(3)
        if new_window:
            self.driver.close()

        # 切换回主窗口
        self.driver.switch_to.window(main_window)
        main_window = None
        new_window = None

    # 错题本
    def page_web_question(self):
        self.base_click(page.student_login_question)
        sleep(2)
        self.base_click(page.student_login_chinese4)
        sleep(2)
        self.base_click(page.student_login_mathe2)

    # 测试业务
    def page_web_try(self):
        self.page_web_login_btn()
        self.page_web_task()
        self.page_web_view()
        self.page_web_start()
        self.base_switch_to_window()
        self.page_web_submit()
        self.page_web_return()
        self.page_web_shijuan()
        self.page_web_gdsj()
        self.page_web_chinese()
        self.page_web_startwrite()
        self.base_switch_to_window()
        self.page_web_tijiao()
        self.page_web_return2()
        self.page_web_video_class()
        self.page_web_training()
        self.base_switch_to_window()
        self.page_web_record()
        self.page_web_record_mathe()
        self.page_web_question()
